﻿// Copyright (C) Norsolutions GmbH
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Reng van Oord
// Created:    2010.05.05


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sherwood.Localization;

namespace Sherwood.Mvc.Localization
{
    /// <summary>
    /// ASP.Net MVC ActionFilter implementation which can be applied to controller classes and/or methods to enable the TranslationOutputFilter on the controllers output (typically a View).
    /// </summary>
    public class TranslationFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext != null && filterContext.HttpContext != null && filterContext.HttpContext.Response != null && filterContext.HttpContext.Response.Filter != null)
            {
                filterContext.HttpContext.Response.Filter = new TranslationOutputFilter(filterContext.HttpContext.Response.Filter, DependencyInjection.Resolve<ITranslationProvider>());
            }

            base.OnActionExecuted(filterContext);
        }

    }
}
